package com.government.member.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.government.member.domain.Vip;
import com.government.member.mapper.VipMapper;
import com.government.member.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class VipServiceImpl implements VipService {
    @Autowired
    private VipMapper vipMapper;

    @Override
    public Vip selectVipByUserId(Long userId, int vipType) {

        return vipMapper.selectOne(Wrappers.<Vip>lambdaQuery()
                .eq(Vip::getUid, userId).
                eq(Vip::getVipType, vipType)
                .eq(Vip::getStatus,"1"));
    }

    @Override
    public int updateVip(Vip vip) {

        return vipMapper.updateById(vip);
    }

    @Override
    public int insertVip(Vip vip) {

        return vipMapper.insert(vip);
    }

    @Override
    public List<Vip> selectExpiredVip() {
        return vipMapper.selectList(Wrappers.<Vip>lambdaQuery()
                .le(Vip::getMaturityTime, DateUtil.date())
                .eq(Vip::getStatus,"1"));
    }
}
